***********************************
*Code to replicate the findings in Hsiung and Djupe (forthcoming) in Political Behavior
*File contains code for the Mechanical Turk dataset
*Date: 3/22/2018
*Dataverse location: URL HERE.
***********************************

*Load the csv data
import delimited "C:\Users\pdjup\Dropbox\Trust\Trust R&R\Clean Data\mt_experiment\mt_data.csv"

*It should default to lower case, but just in case
rename *, lower

*Identifying the treatments.
	*inclusive style
gen t_inc=0
replace t_inc=1 if q4==1
	*exclusive style
gen t_exc=0
replace t_exc=1 if q9==1

*Agreement with the value sets - there were two versions, the primed and not primed
foreach x in 1 2 3 4 5 6 7 {
gen inr`x'=q5_`x' if q5_`x'<.
replace inr`x'=q34_`x' if q34_`x'<.
gen exr`x'=q10_`x' if q10_`x'<.
replace exr`x'=q35_`x' if q35_`x'<.
}

alpha inr*, gen(inr) // a=.86 
gen inrc=(inr-1)/4
alpha exr*, gen(exr) // a=.93
gen exrc=(exr-1)/4


*Dependent variables - The Trusts
gen strust=(5-q17_5)/4 // People too often try and take advantage of others 1=SA 5=SD
gen ptrust=(q17_1-1)/4 // I trust the federal government to do what is right 1=SD 5=SA

*Index versions for one of the reviewers
alpha q17_3 q17_5, r(q17_3 q17_5) gen(sindex) //a=.70
gen sindex2=(-1*sindex-1)/4

alpha q17_1 q17_2,  r(q17_2) gen(pindex) //a=.64
gen pindex2=(pindex+2)/6

*Controls

*Partisanship
gen pid=q29

*Age in years
gen age=2015-q30

*Education
gen ed=q31

*White 
recode q27_1 (.=0), gen(white)

*Female
gen female=q26-1

*Religious Traditions
gen nonrel=0
replace nonrel=1 if q2>8

gen nonchr=0
replace nonchr=1 if q2==3 | q2==4 | q2==6 | q2==7

gen rt_cath=0
replace rt_cath=1 if q2==2

gen rt_evan=0
replace rt_evan=1 if q25<8

*Moral Foundations Purity and Fairness scales
gen purity=(((q23_2+q23_4+q23_6+q24_2+q24_5+q24_6)-6)/29)
gen fairness=(((q23_1+q23_3+q23_5+q24_1+q24_4+q24_7)-8)/28)

*This makes 
*Next run each model -- q19 was an attention check for an embedded experiment and 2 is the (easy) correct answer
reg ptrust i.t_exc##i.nonrel##c.exrc i.t_inc##i.nonrel##c.inrc pid age ed white female rt_cath rt_evan nonchr purity fairness if q19==2
outreg2 using trust_exp.doc, stats(coef pval) side dec(2)
reg pindex2 i.t_exc##i.nonrel##c.exrc i.t_inc##i.nonrel##c.inrc pid age ed white female rt_cath rt_evan nonchr purity fairness if q19==2
outreg2 using trust_exp.doc, stats(coef pval) side dec(2) 
reg strust i.t_exc##i.nonrel##c.exrc i.t_inc##i.nonrel##c.inrc pid age ed white female rt_cath rt_evan nonchr purity fairness if q19==2
outreg2 using trust_exp.doc, stats(coef pval) side dec(2) 
reg sindex2 i.t_exc##i.nonrel##c.exrc i.t_inc##i.nonrel##c.inrc pid age ed white female rt_cath rt_evan nonchr purity fairness if q19==2
outreg2 using trust_exp.doc, stats(coef pval) side dec(2) 

*This generates estimates for Figure 4 in the paper
*Now, running the non-index models from above and run these lines after each
reg ptrust i.t_exc##i.nonrel##c.exrc i.t_inc##i.nonrel##c.inrc q29 q30 q31 white q26 rt_cath rt_evan nonchr purity fairness if q19==2
margins, dydx(inrc) at(nonrel=(0 1) t_inc=(0 1)) l(90)
margins, dydx(exrc) at(nonrel=(0 1) t_exc=(0 1)) l(90)
reg strust i.t_exc##i.nonrel##c.exrc i.t_inc##i.nonrel##c.inrc q29 q30 q31 white q26 rt_cath rt_evan nonchr purity fairness if q19==2
margins, dydx(inrc) at(nonrel=(0 1) t_inc=(0 1)) l(90)
margins, dydx(exrc) at(nonrel=(0 1) t_exc=(0 1)) l(90)

*Combine the margins estimates into a dataset - I copied and pasted them together.
*Place is the order the estimates come out and the plot placement
*Effect is the dydx of value agreement
*lo and hi refer to the confidence intervals.
*exclusive is whether this is t_exc or t_inc priming treatments
*ptrust is whether the est is for inclusive or exclusive
place	effect		lo			hi		exclusive	ptrust
1.1		-.035665	-.218597	.147266		0		0
2.1		.313511		.060823		.566199		0		0
3.1		-.124487	-.233846	-.015129	0		0
4.1		.049165		-.095941	.194271		0		0
.9		.119681		-.119566	.358928		0		1
1.9		.644611		.321508		.967714		0		1
2.9		.028715		-.113068	.170498		0		1
3.9		.071533		-.11711		.260176		0		1
1.1		.055928		-.081021	.192878		1		0
2.1		-.174253	-.33828		-.010225	1		0
3.1		-.049614	-.192654	.093426		1		0
4.1		.20347		-.006228	.413168		1		0
.9		-.205446	-.383253	-.027638	1		1
1.9		-.438935	-.65444		-.22343		1		1
2.9		.153358		-.034297	.341013		1		1
3.9		-.005509	-.281205	.270186		1		1


la def order 1 "Religious, Non-Prime" 2 "Religious, Primed" 3 "None, Non-Primed" 4"None, Primed"
la val place order 

*This code, then, using the mini dataset above makes Figure 4 
twoway scatter place effect if ptrust==1 & exclusive==0, col(black) ///
	|| scatter place effect if ptrust==0 & exclusive==0, ms(Sh) col(black) ///
	|| rspike lo hi place if exclusive==0, hor lc(black) xtitle("Effect of Inclusive Religious Style") ylabel(#4, val angle(hor)) ytitle("") ///
		xline(0) graphregion(color(white)) legend(region(color(white)) order(1 "Political Trust" 2 "Social Trust")) name(inclusive, replace)

twoway scatter place effect if ptrust==1 & exclusive==1, col(black) ///
	|| scatter place effect if ptrust==0 & exclusive==1, ms(Sh) col(black) ///
	|| rspike lo hi place if exclusive==1, hor lc(black) xtitle("Effect of Exclusive Religious Style") ylabel(#4, val angle(hor)) ytitle("") ///
		xline(0) graphregion(color(white)) legend(region(color(white)) order(1 "Political Trust" 2 "Social Trust")) name(exclusive, replace)

graph combine inclusive exclusive, col(2) graphregion(color(white)) xsize(6.5)


